const API_HOST = "https://network.growthupup.com/api"
const ReqClient = (url, method, data) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: API_HOST + url,
      method,
      data,
      success: (res) => resolve(res),
      fail: err => reject(err)
    })
  })
}
/*用户*/
//获取登录信息
export const loginByCode = (code,userInfo) => {
  return ReqClient('/public/index/wechat/login_by_code', 'POST', {
    code,
    ...userInfo    
  })
}
/*全网库存 */
export const allNetwork = (token,form) => {
  return ReqClient('/public/index/product/all_network', 'POST', {
    token,
    ...form
  })
}
/*个人页面加载*/
export const user = ({
  token
}) => {
  return ReqClient('/public/index/user/merchant_profile', 'POST', {
    token
  })
}
//小程序订单（线上订单）列表
export const onlineOrderList = ({
  token,
  page,
  type,
  status,
  id
}) => {
  return ReqClient('/public/index/order/order_list', 'POST', {
    token,
    page,
    type,
    status,
    id
  })
}

// 取消订单
export const cancelOrder = ({
  token,
  batchcode
}) => {
  return ReqClient('/public/index/order/remove', 'POST', {
    token,
    batchcode
  })
}

//确认收货
export const confirmOrder = ({
  token,
  batchcode
}) => {
  return ReqClient('/public/index/order/confirm_order', 'POST', {
    token,
    batchcode
  })
}

//获取商品类目
export const systematicsList = ({
  token,
  parent_id,
}) => {
  return ReqClient('/public/index/product/get_product_category', "POST", {
    token,
    parent_id,
  })
}
/*品牌*/
export const brands = ({
  token
}) => {
  return ReqClient('/public/index/product/get_title', "POST", {
    token
  })
}

export const productDetailNew = ({
  token,
  id
}) => {
  return ReqClient('/public/index/product/get_product_by_id', "POST", {
    token,
    id
  })
}
/*获取默认地址*/
export const defaultadd = ({
  token
}) => {
  return ReqClient('/public/index/delivery/is_defult', 'POST', {
    token
  })
}
/*一件采购*/
export const onePurchase = ({
  token,
  product_ids,
  delivery_id,
  total_price,
  remark
}) => {
  return ReqClient('/public/index/order/add_order', 'POST', {
    token,
    product_ids,
    delivery_id,
    total_price,
    remark
  })
}
/*地址管理*/
export const addressMas = ({
  token,
}) => {
  return ReqClient('/public/index/delivery/address_list', 'POST', {
    token,
  })
}
/*地址删除*/
export const deleteadd = ({
  token,
  id
}) => {
  return ReqClient('/public/index/delivery/del_address', 'POST', {
    token,
    id
  })
}
/*地址添加/修改*/
export const modifyAdd = ({
  token,
  id,
  name,
  phone,
  province,
  city,
  district,
  address,
  is_default,
}) => {
  return ReqClient('/public/index/delivery/add_address', 'POST', {
    token,
    id,
    name,
    phone,
    province,
    city,
    district,
    address,
    is_default,
  })
}
/*获取支付订单详情*/
export const detailsPayment = ({
  token,
  batchcode
}) => {
  return ReqClient('/public/index/order/pay_order', 'POST', {
    token,
    batchcode
  })
}
/*支付*/
export const payment = ({
  token,
  batchcode,
  openid,
  total_fee
}) => {
  return ReqClient('/public/index/wechat/pay', 'POST', {
    token,
    batchcode,
    openid,
    total_fee
  })
}

/*获取openid*/
export const obtain_openid = ({
  code
}) => {
  return ReqClient('/public/index/wechat/get_openid', 'POST', {
    code
  })
}
//图片上传到七牛，向后端获取token接口
export const getToken = () => {
  return ReqClient('/public/index/qiniu/getToken', "POST", {})
}
/*意见反馈*/
export const feedback = ({
  token,
  content,
  contact,
  image
}) => {
  return ReqClient('/public/index/feedback/create', 'POST', {
    token,
    content,
    contact,
    image
  })
}
